package com.dcm.bargain.controller;

import com.dcm.bargain.entity.BargainEntity;
import com.dcm.bargain.service.BargainService;
import com.dcm.common.annotation.EnableResponseBodyAdvice;
import com.dcm.common.exception.MyException;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author:zhouyuhan
 * 时间: 2021/3/27 15:33
 */

@RestController
@RequestMapping("/bargain")
@EnableResponseBodyAdvice
public class BargainController {

    @Autowired
    private BargainService bargainService;

    /**
     * 查找所有
     * @return
     */
    @ApiOperation("查询所有")
    @GetMapping("/findAll")
    public List<BargainEntity> findAll(){
        return bargainService.findAll();
    }

    /**
     * 通过ID删除
     * @param id
     * @throws MyException
     */
    @ApiOperation("通过ID删除")
    @DeleteMapping("/delete")
    public void delete(@RequestParam("id")Long id)throws MyException {
        bargainService.delete(id);
    }

    /**
     * 模糊主键和砍价名称
     * @param id
     * @param bargainName
     * @return
     * @throws MyException
     */
    @ApiOperation("模糊主键和砍价名称")
    @GetMapping("/findbargainByIdAndName")
    public List<BargainEntity> findbargainByIdAndName(@RequestParam(value = "id",required = false)Long id,
                                                      @RequestParam(value = "bargainName",required = false)String bargainName)throws MyException{
        return bargainService.findbargainByIdAndName(id,bargainName);
    }

    /**
     * 添加砍价列表
     * @param bargainEntity
     * @throws MyException
     */
    @ApiOperation("添加")
    @PostMapping("/add")
    public void add(@RequestBody BargainEntity bargainEntity)throws MyException{
        bargainService.add(bargainEntity);
    }

    /**
     * 修改砍价列表
     * @param bargainEntity
     * @throws MyException
     */
    @ApiOperation("修改")
    @PutMapping("/update")
    public void update(@RequestBody BargainEntity bargainEntity)throws MyException{
        bargainService.update(bargainEntity);
    }

    /**
     *回显
     * @param id
     * @return
     * @throws MyException
     */
    @ApiOperation("回显ID")
    @GetMapping("/echo")
    public BargainEntity echo(@RequestParam(value = "id",required = false)Long id)throws MyException{
        return bargainService.echo(id);
    }

    /**
     * 砍价列表分页
     * @param pageSize
     * @param currentPage
     * @return
     * @throws MyException
     */
    @ApiOperation("分页")
    @GetMapping("/findPage")
    public PageInfo<BargainEntity> findPage(@RequestParam(value = "pageSize",required = false)Integer pageSize,
                                             @RequestParam(value = "currentPage",required = false)Integer currentPage)throws MyException{
        return bargainService.findPage(pageSize,currentPage);
    }

    /**
     * 通过id修改状态
     * @param id
     * @param status
     * @throws MyException
     */
    @ApiOperation("修改状态")
    @PutMapping("/updateStatus")
    public void updateStatus(@RequestParam(value = "id",required = false)Long id,
                             @RequestParam(value = "status",required = false)Integer status)throws MyException{
        bargainService.updateStatus(id,status);
    }





}



